﻿using System;
using UnityEngine;

// Token: 0x0200058F RID: 1423
[Serializable]
public class FBSBlinkControl
{
	// Token: 0x06002211 RID: 8721 RVA: 0x001356C8 File Offset: 0x001338C8
	public virtual void SetFixedFlags(byte flags)
	{
		this.fixedFlags = flags;
	}

	// Token: 0x06002212 RID: 8722 RVA: 0x001356D4 File Offset: 0x001338D4
	public virtual byte GetFixedFlags()
	{
		return this.fixedFlags;
	}

	// Token: 0x06002213 RID: 8723 RVA: 0x001356DC File Offset: 0x001338DC
	public virtual void SetFrequency(byte value)
	{
		this.BlinkFrequency = value;
		if ((int)this.blinkMode == 0)
		{
			int num = UnityEngine.Random.Range(0, (int)this.BlinkFrequency);
			float num2 = Mathf.InverseLerp(0f, (float)this.BlinkFrequency, (float)num);
			num2 = Mathf.Lerp(0f, (float)this.BlinkFrequency, num2);
			this.blinkTime = Time.time + 0.2f * num2;
		}
	}

	// Token: 0x06002214 RID: 8724 RVA: 0x00135744 File Offset: 0x00133944
	public virtual void SetSpeed(float value)
	{
		this.BaseSpeed = Mathf.Max(1f, value);
	}

	// Token: 0x06002215 RID: 8725 RVA: 0x00135758 File Offset: 0x00133958
	public virtual void SetForceOpen()
	{
		this.calcSpeed = this.BaseSpeed + UnityEngine.Random.Range(0f, 0.05f);
		this.blinkTime = Time.time + this.calcSpeed;
		this.blinkMode = -1;
	}

	// Token: 0x06002216 RID: 8726 RVA: 0x00135790 File Offset: 0x00133990
	public virtual void SetForceClose()
	{
		this.calcSpeed = this.BaseSpeed + UnityEngine.Random.Range(0f, 0.05f);
		this.blinkTime = Time.time + this.calcSpeed;
		this.count = UnityEngine.Random.Range(0, 3) + 1;
		this.blinkMode = 1;
	}

	// Token: 0x06002217 RID: 8727 RVA: 0x001357E4 File Offset: 0x001339E4
	public virtual void CalcBlink()
	{
		float num = Mathf.Max(0f, this.blinkTime - Time.time);
		sbyte b = this.blinkMode;
		float num2;
		switch (b + 1)
		{
		case 1:
			num2 = 1f;
			goto IL_8A;
		case 2:
			num2 = Mathf.Clamp(num / this.calcSpeed, 0f, 1f);
			goto IL_8A;
		}
		num2 = Mathf.Clamp(1f - num / this.calcSpeed, 0f, 1f);
		IL_8A:
		if (this.fixedFlags == 0)
		{
			this.openRate = num2;
		}
		if (this.fixedFlags != 0)
		{
			return;
		}
		if (Time.time <= this.blinkTime)
		{
			return;
		}
		b = this.blinkMode;
		switch (b + 1)
		{
		case 0:
		{
			int num3 = UnityEngine.Random.Range(0, (int)this.BlinkFrequency);
			float num4 = Mathf.InverseLerp(0f, (float)this.BlinkFrequency, (float)num3);
			num4 = Mathf.Lerp(0f, (float)this.BlinkFrequency, num4);
			this.blinkTime = Time.time + 0.2f * num4;
			this.blinkMode = 0;
			break;
		}
		case 1:
			this.SetForceClose();
			break;
		case 2:
			this.count--;
			if (0 >= this.count)
			{
				this.SetForceOpen();
			}
			break;
		}
	}

	// Token: 0x06002218 RID: 8728 RVA: 0x00135954 File Offset: 0x00133B54
	public virtual float GetOpenRate()
	{
		return this.openRate;
	}

	// Token: 0x04002A85 RID: 10885
	protected byte fixedFlags;

	// Token: 0x04002A86 RID: 10886
	[Range(0f, 255f)]
	public byte BlinkFrequency = 30;

	// Token: 0x04002A87 RID: 10887
	protected sbyte blinkMode;

	// Token: 0x04002A88 RID: 10888
	[Range(0f, 0.5f)]
	public float BaseSpeed = 0.15f;

	// Token: 0x04002A89 RID: 10889
	protected float calcSpeed;

	// Token: 0x04002A8A RID: 10890
	protected float blinkTime;

	// Token: 0x04002A8B RID: 10891
	protected int count;

	// Token: 0x04002A8C RID: 10892
	protected float openRate = 1f;
}
